package com.socialuni.sdk.service;

import com.socialuni.sdk.api.model.ResultRO;
import com.socialuni.sdk.api.OAuthAPI;
import com.socialuni.sdk.user.phone.SocialBindPhoneNumDomain;
import com.socialuni.sdk.exception.SocialParamsException;
import com.socialuni.sdk.factory.user.base.SocialUserDetailROFactory;
import com.socialuni.sdk.user.phone.SocialPhoneNumManage;
import com.socialuni.sdk.model.DO.user.UserDO;
import com.socialuni.sdk.model.RO.OAuthUserPhoneNumRO;
import com.socialuni.sdk.model.RO.SocialUserDetailRO;
import com.socialuni.sdk.repository.SocialUserPhoneRepository;
import com.socialuni.sdk.store.SocialUserPhoneStore;
import com.socialuni.sdk.utils.UserUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class SocialUserBindPhoneNumService {

    @Resource
    SocialUserPhoneStore socialUserPhoneStore;
    @Resource
    SocialUserPhoneRepository socialUserPhoneRepository;
    @Resource
    OAuthAPI oAuthApi;
    @Resource
    SocialPhoneNumManage socialPhoneNumManage;

//    @Resource
//    SocialUserDetailRepository socialUserDetailRepository;

    @Resource
    SocialBindPhoneNumDomain socialBindPhoneNumDomain;

    public SocialUserDetailRO bindSocialPhoneNum() {
        UserDO mineUser = UserUtils.getMineUser();

        ResultRO<OAuthUserPhoneNumRO> resultRO = oAuthApi.getOAuthUserPhoneNum();
        if (resultRO.hasError()) {
            throw new SocialParamsException(resultRO.getErrorMsg());
        }
        String phoneNum = resultRO.getData().getPhoneNum();

        socialBindPhoneNumDomain.checkPhoneNumAndUserBindPhoneNum(mineUser, "86", phoneNum);

        SocialUserDetailRO userDetailVO = SocialUserDetailROFactory.getMineUserDetail(mineUser);
        return userDetailVO;
    }
}